xend: Check no VBDs attached on VDI.destroy
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 16 Oct 2009 07:35:21 +0000 (08:35 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 16 Oct 2009 07:35:21 +0000 (08:35 +0100)
We can destroy a VDI by VDI.destroy even if the VDI is being used
to VBDs. This patch checks that the VDI is not used to VBDs.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendError.py

index 975766bcd7dabf08e55ba27c12cea2cbf7259ded..a489db01b157b6cc26acbd44de9b82f8e7017d37 100644 (file)
@@ -2370,6 +2370,12 @@ class XendAPI(object):
     # Object Methods
     
     def VDI_destroy(self, session, vdi_ref):
+        # check no VBDs attached
+        image = XendNode.instance().get_vdi_by_uuid(vdi_ref)
+        if image.getVBDs():
+            raise VDIError("Cannot destroy VDI with VBDs attached",
+                           image.name_label)
+
         sr = XendNode.instance().get_sr_containing_vdi(vdi_ref)
         sr.destroy_vdi(vdi_ref)
         return xen_api_success_void()
index c0b00765259432ac76dac4f48bbbd76673b26662..a78f5f4f081927e0ceaf915bbef60079c90e91a6 100644 (file)
@@ -186,6 +186,18 @@ class DirectPCIError(XendAPIError):
     def __str__(self):
         return 'DIRECT_PCI_ERROR: %s' % self.error
 
+class VDIError(XendAPIError):
+    def __init__(self, error, vdi):
+        XendAPIError.__init__(self)
+        self.vdi = vdi
+        self.error = error
+
+    def get_api_error(self):
+        return ['VDI_ERROR', self.error, self.vdi]
+
+    def __str__(self):
+        return 'VDI_ERROR: %s %s' % (self.error, self.vdi)
+
 from xen.util.xsconstants import xserr2string
 
 class SecurityError(XendAPIError):